<template>
  <div class="app-container book">
    <div class="content">
      <div class="block" v-for="(item,index) in list" :key="index" @click="goToInfo(item.bookId,item.columnId,item.bookName)">
        <div class="item">
          <img class="item-cover" :src="item.cover" alt="">
          <div class="item-right">
            <span class="name" v-html="item.bookName">生而不返</span>
            <span class="author" v-html="item.author">{{item.author}}</span>
            <span class="desc">{{item.press}}</span>
          </div>
        </div>
      </div>
    </div>
    <div class="pagination">
      <el-pagination @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-size="10" layout="total, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getBookList } from "@/api/index";
export default {
  data() {
    return {
      currentPage: Number(this.$route.query.currentPage) || 1,
      total: 0,
      list: [],
      
    };
  },
  components: {},
  created() {
    this.getBookList(this.currentPage);
    console.log(this.columnId);
  },
  watch: {
    columnId() {
      this.currentPage = Number(this.$route.query.currentPage) || 1,
      // this.$router.push(this.$route.path + "?currentPage=" + this.currentPage);
      this.getBookList(this.currentPage);
    },
    $route() {
      this.currentPage = Number(this.$route.query.currentPage) || 1;
      this.getBookList(this.currentPage);
    }
  },
  computed: {
    columnId() {
      return this.$store.state.columnId;
    },
    columnTwoId() {
      return this.$store.state.columnTwoId;
    }
  },
  methods: {
    getBookList(page, pageSize) {
      getBookList(page, pageSize)
        .then(res => {
          console.log(res.data);
          this.total = res.data.total;
          this.list = res.data.data;
          this.currentPage = Number(this.$route.query.currentPage) || 1;
        })
        .catch(err => {
          console.log(err);
        });
    },
    goToInfo(bookId, columnId,bookName) {
      this.$router.push("/book/info?bookId=" + bookId + "&columnId=" + columnId+ "&bookName=" + bookName);
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      // this.currentPage = val;
      this.$router.push(this.$route.path + "?currentPage=" + this.currentPage+"&columnId="+this.columnId);
    }
  }
};
</script>
<style lang="less" scoped>
.book {
  padding: 0px 20px 20px 20px;
  border-radius: 10px;
  background: #fff;
  .content {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    margin-bottom: 30px;
    border-bottom: 1px solid #eaeaea;
    .block {
      width: 480px;
      margin-top: 20px;
      padding-bottom: 24px;
      border-bottom: 1px solid #eaeaea;
      margin-bottom: -1px;
      .item {
        display: flex;
        cursor: pointer;
        .item-cover {
          width: 120px;
          height: 160px;
          border-radius: 10px;
          box-shadow: 0 2px 10px rgba(0,0,0,0.4);
        }
        .item-right {
          flex: 1;
          display: flex;
          flex-direction: column;
          margin-left: 20px;
          .name {
            font-size: 18px;
            margin-top: 10px;
          }
          .author {
            font-size: 14px;
            color: #a1a1a1;
            margin-top: 5px;
          }
          .desc {
            font-size: 14px;
            color: #868686;
            margin-top: 5px;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
            overflow: hidden;
          }
          .time {
            font-size: 12px;
            color: #c1c1c1;
            margin-top: 20px;
          }
        }
      }
    }
    .block:nth-child(2n) {
      padding-left: 194px;
    }
  }
}
</style>


